<template>
  <div>
    <div ref="myChart" :style="{ width: '800px', height: '400px' }"></div>
  </div>
</template>

<script setup lang="ts">
// 引入echarts
import request from '@/util/request'
import * as echarts from 'echarts'
import { ref, onMounted } from 'vue'

// 获取div的dom元素
const myChart = ref(null)
const getOption = async () => {
  const { data, meta } = await request({
    url: '/reports/type/1',
    method: 'GET',
  })
  // 配置信息
  const option = {
    title: {
      text: '用户来源',
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#E9EEF3',
        },
      },
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true,
    },
    xAxis: [
      {
        boundaryGap: false,
      },
    ],
    yAxis: [
      {
        type: 'value',
      },
    ],
  }
  // 初始化一个echarts的图
  const chart = echarts.init(myChart.value)
  // 将后面的数据添加在前面
  Object.assign(option, data)
  chart.setOption(option)
}

onMounted(() => {
  // 获取配置信息
  getOption()
})
</script>

<style scoped>
.el-col {
  border: 1px solid #000;
}
</style>
